package com.love.marriage.userMembershipHistory.service.impl;

import com.love.marriage.userMembershipHistory.entity.UserMembershipHistory;
import com.love.marriage.userMembershipHistory.vo.UserMembershipHistoryVo;
import com.love.marriage.userMembershipHistory.mapper.UserMembershipHistoryMapper;
import com.love.marriage.userMembershipHistory.service.UserMembershipHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import com.love.marriage.utils.StringUtils;

/**
 * <p>
 * description:  用户会员历史记录表服务实现类
 * author:       mybatisPlus
 * createDate:   2025-06-27 07:07:06
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserMembershipHistoryServiceImp extends ServiceImpl<UserMembershipHistoryMapper, UserMembershipHistory> implements UserMembershipHistoryService {

    private final UserMembershipHistoryMapper userMembershipHistoryMapper;

    @Override
    public Page<UserMembershipHistoryVo> getPage(Long pageNum, Long pageSize, UserMembershipHistoryVo userMembershipHistoryVo) {
        Page<UserMembershipHistoryVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userMembershipHistoryMapper.getPage(page, userMembershipHistoryVo);
    }

    @Override
    public UserMembershipHistoryVo queryUserMembershipHistory(Long id) {
        return userMembershipHistoryMapper.queryUserMembershipHistory(id);
    }

    @Override
    public UserMembershipHistoryVo addUserMembershipHistory(UserMembershipHistoryVo userMembershipHistoryVo) {
        UserMembershipHistory userMembershipHistory = new UserMembershipHistory();
        BeanUtils.copyProperties(userMembershipHistoryVo, userMembershipHistory);
        userMembershipHistoryMapper.insert(userMembershipHistory);
        UserMembershipHistoryVo res = new UserMembershipHistoryVo();
        BeanUtils.copyProperties(userMembershipHistory, res);
        return res;
    }

    @Override
    public UserMembershipHistoryVo updateUserMembershipHistory(UserMembershipHistoryVo userMembershipHistoryVo) {
        UserMembershipHistory userMembershipHistory = new UserMembershipHistory();
        BeanUtils.copyProperties(userMembershipHistoryVo, userMembershipHistory);
        userMembershipHistoryMapper.updateById(userMembershipHistory);
        return userMembershipHistoryVo;
    }

    @Override
    public Boolean deleteUserMembershipHistory(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userMembershipHistoryMapper.deleteBatchIds(idArr);
        return true;
    }
}
